package cn.taobaoke.restful.util;

import com.google.gson.Gson;

import java.util.Map;

/**
 * Json工具类.
 *
 * @author yangzuo
 * @since 2017-03-27
 */
public class GsonUtil {

    private static final Gson gson = new Gson();

    public static String getJsonString(Object obj) {
        return gson.toJson(obj);
    }

    public static Map<String, Object> getObject(String json) {
        return gson.fromJson(json, Map.class);
    }

    public static Object getItemByKey(String json, String key) {
        return gson.fromJson(json, Map.class).getOrDefault(key, null);
    }
}
